<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<meta name="apple-mobile-web-app-capable" content="no" />
	<title>产品管理</title>
    <link rel="stylesheet" type="text/css" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/css/SUI.css?v">
	<link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.min.css">
    <link rel="stylesheet" type="text/css" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/font/iconfont.css">
    <link rel="stylesheet" type="text/css" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/app.css?v=1">
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/app.css?v=1" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/all.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/dropload.css" rel="stylesheet" />
	<style type="text/css">
		.PrdLineStyle{padding-top: 50px;}
		.orders_all{width: 100%;padding-bottom: 10px;z-index: 10}
		.orders_all ul li{margin-bottom: 0;}
		.orders_all ul{background: #fff}
		.noproduct{height: calc(100vh - 55px);background: url('/static/wechat/img/noproduct.png') no-repeat;background-size: 63%;background-position: center;}
	</style>
</head>
<body class="storeprd">
	<div class="orders_all">
		<ul>
			<li><a class="qh on" data-cid="">全部产品</a></li>
			{{range .column}}
			<li><a class="qh" data-cid="{{.id}}">{{.name}}</a></li>
			{{end}}
		</ul>
	</div>
	<div class="PrdLineStyle">
		{{range .info}}
		<dl class="list" id="{{.id}}" data-cid="{{.gcid}}">
			<dt><img src="{{.pathname}}" alt="">
			{{if eq .censoring "1"}}
			<label class="on">正常销售</label>
			{{else}}
			<label class="down">下架产品</label>
			{{end}}
			</dt>
			<dd>
				<p>{{.title}}</p>
				<p>{{range .keywords}}<span>{{.title}}</span>{{end}}</p>
				<p><span><span>&yen;</span>{{.price}}</span>{{.sellnum}}人购买</p>
			</dd>
			<dd>
				<span class="del" data-id="{{.id}}">删除产品</span>
				{{if eq .censoring "1"}}
				<span class="censoring" data-id="{{.id}}" data-status="1">下架产品</span>
				{{else}}
				<span class="censoring" data-id="{{.id}}" data-status="0">上架产品</span>
				{{end}}
				<span class="goto" href="/mobile/column/product_content?id={{.id}}">查看产品</span>
			</dd>
		</dl>
		{{end}}
		<div class="noproduct" style="display: none;">
				
		</div>
	</div>
</body>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/echarts-all.js?1"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/js/SUI.js?1"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/zepto.min.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/dropload.min.js"></script>
<script type="text/javascript">
	var cid=''
	mui('body').on('tap','.qh',function(){
		mui(".qh").each(function(){
			this.className = "qh"
		});
		this.className = "qh on"
		cid=this.getAttribute('data-cid')
		qh()
	})
	var list=document.getElementsByClassName('list')
	var noproduct=document.getElementsByClassName('noproduct')[0]
	function qh(){
		noproduct.style.display='none'
		var num=0
		if(cid==""){
			for(var i=0;i<list.length;i++){
				num+=1
				list[i].style.display='block'
			}
		}else{
			for(var i=0;i<list.length;i++){
				var type=list[i].getAttribute("data-cid")
				if(cid==type){
					num+=1
					list[i].style.display='block'
				}else{
					list[i].style.display='none'
				}
			}
		}
		if(num==0){
			noproduct.style.display='block'
		}
	}
	qh()
</script>
<script>
	mui('body').on('tap','.del',function(){
		var id=this.getAttribute("data-id")
		var that=this
		that.disabled=true
		mui.confirm("您确定要删除该产品吗?","提示",function(data){
			if(data.index){
				mui.ajax("/mobile/my/shop_product_del",{
					data:{id:id},
					type:'post',
					timeout:1000,
					success:function(res){
						that.disabled=false
						if(res){
							mui.toast("删除成功~")
							var p=that.parentNode.parentNode
							p.parentNode.removeChild(p)
						}else{
							mui.toast("网络繁忙,请稍后再试~")
						}
					},error:function(){
						mui.toast("网络繁忙,请稍后再试~")
						that.disabled=false
					}
				})
			}else{
				that.disabled=false
			}
		})
	})
	mui('body').on('tap','.censoring',function(){
		var id=this.getAttribute("data-id")
		var status=this.getAttribute("data-status")
		var that=this
		that.disabled=true
		var tip=''
		var to=''
		if(status==1){
			tip="您确定要下架该产品吗?"
			to="下架成功"
		}else{
			tip="您确定要上架该产品吗?"
			to="上架成功"
		}
		mui.confirm(tip,"提示",function(data){
			if(data.index){
				mui.ajax("/mobile/my/shop_product_del",{
					data:{id:id,status:status},
					type:'get',
					timeout:1000,
					success:function(res){
						that.disabled=false
						if(res.status==1){
							mui.toast(to)
							if (res.censoring==0) {
								that.innerHTML="上架产品"
								that.parentNode.parentNode.getElementsByTagName('label')[0].innerHTML="下架产品"
								that.parentNode.parentNode.getElementsByTagName('label')[0].className="down"
							}else{
								that.innerHTML="下架产品"
								that.parentNode.parentNode.getElementsByTagName('label')[0].innerHTML="正常销售"
								that.parentNode.parentNode.getElementsByTagName('label')[0].className="on"
							}
							that.setAttribute("data-status", res.censoring)
						}else{
							mui.toast("网络繁忙,请稍后再试~")
						}
					},error:function(){
						mui.toast("网络繁忙,请稍后再试~")
						that.disabled=false
					}
				})
			}else{
				that.disabled=false
			}
		})
	})
	var page=2;
	$('.element').dropload({
    scrollArea : window,
    threshold: 2,
    loadDownFn : function(me){
        $.ajax({
            type: 'GET',
            url: window.location.href,
            dataType: 'json',
            data:{page:page},
            success: function(data){
			  var res=data.info
              page+=1
              if(res){
                 for (var i=0;i<res.length;i++){
                    var dl = document.createElement('dl');
                    dl.className="list"	
                    dl.setAttribute("id", res[i].id)
                    dl.setAttribute("data-cid", res[i].gcid)
 					var	html=`<dt><img src="`+res[i].pathname+`" alt="">`
 					if(res[i].censoring==1){
 						html+=`<label class="on">正常销售</label>`
 					}else{
 						html+=`<label class="down">下架产品</label>`
 					}
 					html+=`</dt><dd><p>`+res[i].title+`</p><p>`
 					if(res[i].keywords){
 						for(var j=0;j<res[i].keywords.length;j++){
 							html+=`<span>`+res[i].keywords[j].title+`</span>`
 						}
 					}
 					html+=`</p><p><span><span>&yen;</span>`+res[i].price+`</span>`+res[i].sellnum+`人购买</p></dd>
					<dd><span class="del" data-id="`+res[i].id+`">删除产品</span>`
					if(res[i].censoring==1){
 						html+=`<span class="censoring" data-id="`+res[i].id+`" data-status="1">下架产品</span>`
 					}else{
 						html+=`<span class="censoring" data-id="`+res[i].id+`" data-status="0">上架产品</span>`
 					}
 					html+=`<span class="goto" href="/mobile/column/product_content?id=`+res[i].id+`">查看产品</span></dd>`
                    dl.innerHTML=html
                    document.getElementsByClassName('PrdLineStyle')[0].appendChild(dl)
                    qh()
                }
                me.resetload();
                }else{
                    mui.toast("没有更多了！");
                    $(".dropload-down").remove();
                }
            },
            error: function(xhr, type){
                mui.toast("网络慢，请重新刷新!");
                me.resetload();
            }
        });
    }
});
</script>
</html>